{Test package Pixel16u} var h,v,n: integer; a,b,out: integer; kx,ky,kw,kh: integer; kernelPid: integer; xlate16uto8Pid, ymin, ymax: integer; macro 'InsetROI 1'; begin InsetROI(1); end; macro 'Test NormSInv'; var prob: real; begin prob := GetNumber('Probability',0.908789); ShowMessage('NormSInv(',prob:0:8,') = ',NormSInv(prob):0:8); end; macro 'Fill ROI with Normally distributed random noise'; var mu,sigma,seed: real; begin mu := GetNumber('mean',32767); sigma := GetNumber('standard deviation',10000); seed := 1.0; GaussRand16u(mu,sigma,seed,picNumber); end; macro 'Front image is data'; begin RequiresUser('Markup',1); MarkupData8(picNumber); end; macro 'Front image is data16'; begin MarkupData16(picNumber); end; macro 'Front image is bkg'; begin MarkupBkg(picNumber); end; macro 'Select data image'; begin SelectPic(MarkupPicNumber('data')); end; macro 'Select data16 image'; begin SelectPic(MarkupPicNumber('data16')); end; macro 'Select marks image'; begin SelectPic(MarkupPicNumber('mark')); end; macro 'Select bkg image'; begin SelectPic(MarkupPicNumber('bkg')); end; macro 'Show markup'; begin MarkupShow; end; macro 'Open a view on 16 bit image'; begin NewView16u(picNumber,xlate16uto8Pid); end; macro 'Bring 16 bit view --if any-- to front'; begin FindView16u(picNumber); end; macro '[h] set horizontal coordinate'; begin h := getNumber('h = ',h); end; macro '[v] set vertical coordinate'; begin v := getNumber('v = ',v); end; macro '[n] set value to store next'; begin n := getNumber('n = ',n); end; macro '[g] getpixel16u'; begin requiresUser('pixel16u',1); showMessage('getpixel16u = ',getpixel16u(picNumber,h,v)); end; macro '[p] putpixel16u'; begin requiresUser('pixel16u',1); putpixel16u(picNumber,h,v,n); end; macro 'make ROI outside image'; begin makeRoi(20,20,1000,1000); end; macro 'make ROI on odd position'; begin makeRoi(1,1,100,100); end; macro 'make ROI of odd width'; begin makeRoi(2,2,101,101); end; macro 'Add16u current image'; {for testing ROI validation} begin Add16u(picNumber,picNumber,picNumber); end; macro 'make image of odd width'; begin requiresUser('pixel16u',1); {MakeNewWindow rounds requested width up} SetCustom(101,100,0,1); PutMessage('import a file, any file...'); Import(''); end; macro 'convert front 8 bit image to 16 bits'; var i: integer; inPid, xlatePid, outPid: integer; width, height: integer; begin SaveState; inPid := pidNumber; GetPicSize(width,height); SetNewSize(512,1); SetBackgroundColor(0); MakeNewWindow('8 to 16 conversion table'); xlatePid := pidNumber; for i := 0 to 255 do putpixel(i*2,0,i); MakeRoi(0,0,512,1); SetNewSize(width*2,height); MakeNewWindow('16 bit image from ',inPid:0); outPid := pidNumber; RestoreState; Cnvrt8to16u(inPid,xlatePid,outPid); end; macro 'front image is 16 to 8 conversion table'; begin xlate16uto8Pid := pidNumber; end; macro 'set 16 to 8 conversion parameters'; begin ymin := GetNumber('minimum 8 bit pixel value',1); ymax := GetNumber('maximum 8 bit pixel value',254); end; macro 'make 16 to 8 conversion table'; var i,j, x, y: integer; width, height: integer; inPid, min,max: integer; begin RequiresUser('pixel16u',1); if ymax = 0 then begin ymin := GetNumber('minimum 8 bit pixel value',1); ymax := GetNumber('maximum 8 bit pixel value',254); end; SaveState; inPid := pidNumber; minMax16u(inPid,min,max); SetNewSize(256,256); SetBackgroundColor(0); MakeNewWindow('16 to 8 conversion table'); xlate16uto8Pid := pidNumber; linLUT16uto8(xlate16uto8Pid,min,max,ymin,ymax); end; macro 'convert front 16 bit image to 8 bits'; var i,j, x, y: integer; inPid, outPid: integer; width, height: integer; min,max: integer; begin RequiresUser('pixel16u',1); inPid := pidNumber; GetPicSize(width,height); SaveState; ChoosePic(xlate16uto8Pid); MakeRoi(0,0,256,256); SetNewSize(width div 2,height); MakeNewWindow('8 bit image from ',inPid:0); outPid := pidNumber; RestoreState; Cnvrt16uto8(inPid,xlate16uto8Pid,outPid); end; macro 'front image is a'; begin a := pidNumber; end; macro 'front image is b'; begin b := pidNumber; end; macro 'front image is out'; begin out := pidNumber; end; macro 'add out = a + b'; begin add16u(a,b,out); end; macro 'subtract out = a - b'; begin sub16u(a,b,out); end; macro 'multiply out = a * b'; begin mpy16u(a,b,out); end; macro 'divide out = a divide b'; begin div16u(a,b,out); end; macro 'smaller, out = smaller of a, b'; begin sml16u(a,b,out); end; macro 'larger, out = larger of a, b'; begin lrg16u(a,b,out); end; macro 'add out = a + constant'; begin addK16u(a,out,getnumber('constant',0)); end; macro 'subtract out = a - constant'; begin subK16u(a,out,getnumber('constant',0)); end; macro 'multiply out = a * constant'; begin mpyK16u(a,out,getnumber('constant',0)); end; macro 'divide out = a divide constant'; begin divK16u(a,out,getnumber('constant',0)); end; macro 'smaller, out = smaller of a, constant'; begin smlK16u(a,out,getnumber('constant',0)); end; macro 'larger, out = larger of a, constant'; begin lrgK16u(a,out,getnumber('constant',0)); end; procedure setKernelSize; begin kx := trunc(GetNumber('kernel center x',kx)); ky := trunc(GetNumber('kernel center y',ky)); kw := trunc(GetNumber('kernel width',kw)); kh := trunc(GetNumber('kernel height',kh)); end; macro 'set kernel size'; begin setKernelSize; end; macro 'create Kernel'; var x, y: integer; frontImage: integer; sum: real; begin RequiresUser('getputpixel',1); frontImage := pidNumber; if frontImage = kernelPid then frontImage := 0; if kernelPid <> 0 then begin x := kernelPid; kernelPid := 0; SelectPic(x); Dispose; end; if (kx = 0) or (ky = 0) or (kw = 0) or (kh = 0) then begin kx := 2; ky := 2; kw := 5; kh := 5; end; SaveState; SetNewSize(kw * 4, kh); MakeNewWindow('kernel ', kx : 0, 'x ', ky : 0, 'y ', kw : 0, 'w ', kh : 0, 'h'); kernelPid := pidNumber; RestoreState; sum := 0.0; for x := -kx to kw - kx - 1 do begin for y := -ky to kh - ky - 1 do begin sum := sum + exp(-sqrt(sqr(x) + sqr(y))); end; end; sum := 32000.0 / sum; {nearly maximum before overflow on 65535 pixel} for x := -kx to kw - kx - 1 do begin for y := -ky to kh - ky - 1 do begin putPixel32s(kernelPid, x+kx, y+ky, sum * exp(-sqrt(sqr(x) + sqr(y)))); end; end; sum := 0.0; for x := -kx to kw - kx - 1 do begin for y := -ky to kh - ky - 1 do begin sum := sum + getPixel32s(kernelPid, x+kx, y+ky); end; end; showmessage('kernel sum = ',sum); SelectPic(kernelPid); MakeRoi(0,0,kw*4,kh); if frontImage <> 0 then SelectPic(frontImage); end; macro 'Front image is kernel'; begin kernelPid := PidNumber; end; macro 'Convolve front image with kernel'; var height,width,wpix,inPid, maskPid, flagPid, outPid: integer; begin inpid := pidNumber; GetPicSize(width,height); SaveState; SetNewSize(width,height); wpix := width div 2; MakeNewWindow('convolved ',inpid:0,' with kernel ',kernelPid:0); outPid := pidNumber; SetNewSize(wpix, height); MakeNewWindow('flag for ',inpid:0); flagPid := pidNumber; SetNewSize(wpix+kw-1,height+kh-1); MakeNewWindow('mask for ',inpid:0); maskPid := pidNumber; RestoreState; {SetExtraColors(6); no such command} SetForegroundColor(1); MakeRoi(0,0,kx,height+kh); Fill; SetForegroundColor(2); MakeRoi(kx+wpix,0,kw-kx-1,height+kh) Fill; SetForegroundColor(3); MakeRoi(kx,0,wpix,ky); Fill; SetForegroundColor(4); MakeRoi(kx,ky+height,wpix,kh-ky-1); Fill; MakeRoi(kx,ky,wpix,height); Convolve16u(flagPid,inPid,kernelPid,kx,ky,maskPid,outPid); {alphabetical order} end; macro 'Test error checks Convolve front image with kernel'; var height,width,wpix,inPid, maskPid, flagPid, outPid: integer; begin inpid := pidNumber; GetPicSize(width,height); SaveState; SetNewSize(width,height); wpix := width div 2; MakeNewWindow('convolved ',inpid:0,' with kernel ',kernelPid:0); outPid := pidNumber; SetNewSize(wpix, height); MakeNewWindow('flag for ',inpid:0); flagPid := pidNumber; {see if it accepts too small mask} SetNewSize(wpix+kw-1,height+kh-1); SetNewSize(wpix+kw-2,height+kh-2); MakeNewWindow('mask for ',inpid:0); maskPid := pidNumber; RestoreState; {SetExtraColors(6); no such command} SetForegroundColor(1); MakeRoi(0,0,kx,height+kh); Fill; SetForegroundColor(2); MakeRoi(kx+wpix,0,kw-kx-1,height+kh) Fill; SetForegroundColor(3); MakeRoi(kx,0,wpix,ky); Fill; SetForegroundColor(4); MakeRoi(kx,ky+height,wpix,kh-ky-1); Fill; MakeRoi(kx,ky,wpix,height); Convolve16u(flagPid,inPid,kernelPid,kx,ky,maskPid,outPid); {alphabetical order} end; macro 'Dilate8 front image to new image'; var height,width, inPid, outPid, t: integer; begin requiresUser('markup',1); t := GetNumber('thresh',1); inpid := pidNumber; GetPicSize(width,height); SaveState; SetNewSize(width,height); MakeNewWindow('Dilated ',inpid:0); outPid := pidNumber; RestoreState; SelectPic(inPid); MakeRoi(1,1,width-2,height-2); SelectPic(outPid); MakeRoi(1,1,width-2,height-2); Dilate8Mark(inPid, outPid, t); end;